﻿@{
    ViewBag.Title = "CorpManage";
}

@section scripts
{   
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/common/export.js")" type="text/javascript"></script>
}
   <div class="mini-splitter" style="width:100%;height:100%;">
        <div size="390" showcollapseButton="true">
                <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
                    <table style="width:100%;">
                        <tr>
                            <td style="width:100%;">
                                <a class="mini-button" id="fresh" name="fresh" iconCls="icon-search" onclick="LoadAgentList()" plain="true">刷新</a>
                                <span class="separator"></span>
                                <a class="mini-button" id="modifyAgent" name="modifyAgent" iconCls="icon-edit" onclick="modifyAgent" plain="true" visible="@ViewBag.Recharge">修改</a>
                                <a class="mini-button" id="CancelAgent" name="CancelAgent" iconCls="icon-cancel" onclick="CancelAgent" plain="true" visible="@ViewBag.Recharge">取消服务商</a>
                                <a class="mini-button" id="Recharge" name="Recharge" iconCls="icon-tip" onclick="Recharge" plain="true" visible="@ViewBag.Recharge">充值</a>
                                <a class="mini-button" id="setPrice" name="setPrice" iconCls="icon-ok" onclick="setPrice" plain="true" visible="@ViewBag.Recharge">价格设置</a>
                            </td>
                        </tr>
                    </table>
                </div>
                    <table>
                        <tr>
                            <td width ="100px" align="right">编码或名称: </td>
                            <td width ="150px" ><input class="mini-textbox" width ="150px" id ="FSearchKey" name = "FSearchKey" onkeypress="setkeyPress()"/></td>
                            <td width ="100px" align="center">
                            </td>
                        </tr>
                    </table>                
                <div class="mini-fit" >
                    <div id="datagrid2" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                        borderStyle="border:1;" url="GetAgentList"
                        allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true"fitColumns="false"  
                        onrowdblclick="modifyAgent"  sortMode="client" onselectionchanged="select">
                        <div property="columns">
                            <div type="checkcolumn" >选行</div>                            
                            <div field="FNumber" name="FNumber" width="60" headeralign="center" allowsort="true">编码</div>
                            <div field="FName" name="FName" width="130" headeralign="center" allowsort="true">服务商名称</div>
                            <div field="InviteCode" name="InviteCode" width="60" headeralign="center" allowsort="true">邀请码</div>
                            <div field="FAmount" name="FAmount" width="80" headeralign="center" align="right" allowsort="true" numberFormat="#,0.00">帐户余额</div>
                            <div field="FManager" name="FManager" width="80" headeralign="center" allowsort="true">联系人</div>
                            <div field="FTelephone" name="FTelephone" width="100" headeralign="center" allowsort="true">联系电话</div>
                            <div field="FCreatDate" name="FCreatDate" dateFormat="yyyy-MM-dd" width="80" headeralign="center" allowsort="true">注册时间</div>
                        </div>
                    </div>
                </div>
        </div>
        <div showCollapseButton="true">
                <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
                    <table style="width:100%;">
                        <tr>
                            <td style="width:100%;">
                                <a class="mini-button" id="fresh" name="fresh" iconCls="icon-search" onclick="LoadListData('0')" plain="true">刷新</a>
                                <span class="separator"></span>
                                <a class="mini-button" id="new" name="new" iconCls="icon-new" onclick="newBill" plain="true">新增</a>
                                <a class="mini-button" id="save" name="save" iconCls="icon-edit" onclick="modify" plain="true">修改</a>                                                            
                                <a class="mini-button" id="Expiry" name="Expiry" iconCls="icon-goto" onclick="setExpiry" plain="true">系统激活</a>                                
                                <a class="mini-button" id="paypara" name="paypara" iconCls="icon-tip" onclick="setParam" plain="true">支付参数</a>
                                <a class="mini-button" id="saveSign" name="saveSign" iconCls="icon-ok" onclick="setSaveSign" plain="true">审核签名</a>
                                <a class="mini-menubutton" plain="true" iconCls="icon-expand" menu="#popupMenu">选项</a>
                                <span class="separator"></span>
                                <a class="mini-button" id="close" name="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                            </td>
                        </tr>
                    </table>       
                </div>
                    <table>
                        <tr>
                            <td width ="80px" align="right">商户搜索: </td>
                            <td width ="150px" ><input class="mini-textbox" width ="150px" id ="FSearchKey1" name = "FSearchKey1" onkeypress="setkeyPress1()"/></td>
                            <td width="80px" align="right">上级商户：</td>
                            <td width="310px" >
                                @Html.Partial("~/Views/Modular/LookupCorpInfo.cshtml")
                            </td>
                        </tr>
                    </table> 
                    <table> 
                        <tr>
                            <td width="80px" align="right">到期日期:</td>
                            <td width="310px" >
                                @Html.Partial("~/Views/Modular/dxDateRange.cshtml") 
                            </td>
                            <td width ="100px" >
                                <div id="FAtDate" name="FAtDate"  class="mini-checkbox" style ="margin-right:20px" readOnly="false" value ="false" text="按到期日期过滤">
                            </td>
                            <td width ="100px" >
                                <div id="FAtClass" name="FAtClass"  class="mini-checkbox" style ="margin-right:20px" readOnly="false" value ="true" text="按代理商过滤">
                            </td>
                            <td width ="100px" >
                                <div id="FAtApply" name="FAtApply"  class="mini-checkbox" style ="margin-right:20px" readOnly="false" value ="false" text="按签名申请日期">
                            </td>
                        </tr>
                    </table>                
                <div class="mini-fit" >
                    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                        borderStyle="border:1;" url="../Corp/GetCorpList"
                        allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true"fitColumns="false"  
                        onrowdblclick="modify"  sortMode="client">
                        <div property="columns">
                            <div type="checkcolumn" >选行</div>
                            <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
                            <div field="FRegUserNumber" name="FRegUserNumber" width="100" headeralign="center" allowsort="true">注册用户</div>
                            <div field="FItemID" name="FItemID" width="60" headeralign="center" allowsort="true">商户ID</div>
                            <div field="FNumber" name="FNumber" width="80" headeralign="center" allowsort="true">商户编码</div>
                            <div field="FName" name="FName" width="130" headeralign="center" allowsort="true">商户名称</div>                          
                            <div field="FTelephone" name="FTelephone" width="100" headeralign="center" allowsort="true">联系电话</div>
                            <div field="FCreatDate" name="FCreatDate" dateFormat="yyyy-MM-dd hh:mm:ss" width="130" headeralign="center" allowsort="true">注册时间</div>
                            <div field="FEndTime" dateFormat="yyyy-MM-dd" name="FEndTime" width="130" headeralign="center" allowsort="true">到期时间</div> 
                            <div field="FSmsSign" name="FSmsSign" width="100" headeralign="center" allowsort="true">短信签名</div>
                            <div field="FCheckSignFlag" type="checkboxcolumn" name="FCheckSignFlag" trueValue="1" falseValue="0" width="60" headeralign="center" allowsort="true">签名审核</div>                    
                            <div field="FApplyDate" name="FApplyDate" dateFormat="yyyy-MM-dd hh:mm:ss" width="130" headeralign="center" allowsort="true">签名申请时间</div>                             
                            <div field="FAcCode" name="FAcCode" width="80" headeralign="center" allowsort="true">首年激活码</div>                        
                            <div field="FInitialPsd" name="FInitialPsd" width="80" headeralign="center" allowsort="true">初始密码</div>
                            <div field="FParentNumber" name="FParentNumber" width="100" headeralign="center" allowsort="true">上级商户编码</div>
                            <div field="FParentName" name="FParentName" width="150" headeralign="center" allowsort="true">上级商户名称</div> 
                            <div field="FStockName" name="FStockName" width="150" headeralign="center" allowsort="true">门店</div>
                            <div field="FClassName" name="FClassName" width="180" headeralign="center" allowsort="true">服务商名称</div>
                            <div field="FRemark" name="FRemark" width="100" headeralign="center" allowsort="true">备注</div>
                            <div field="FAddress" name="FAddress" width="100" headeralign="center" allowsort="true">地址</div>
                            <div field="FManager" name="FManager" width="80" headeralign="center" allowsort="true">联系人</div>
                        </div>
                    </div>
                </div>
        </div>
   </div>

    <ul id="popupMenu" class="mini-menu" style="display:none;">
        <li id="Agent" name="Agent" iconCls="icon-ok" onclick="setAgent" visible="@ViewBag.Recharge">设为服务商</li>
        <span class="separator"></span>
        <li id ="ClearPos" name="ClearPos" iconCls="icon-tip" onclick="setClearPOS()" visible="@ViewBag.Recharge">注销前台</li>
        <li id ="delCorp" name="delCorp" iconCls="icon-remove" onclick="delCorp()" visible="@ViewBag.Recharge">注销商户</li>
        <span class="separator"></span>
    </ul>                                
<script>
    mini.parse();
    function FormShown() {        
        var nowDate = new Date();
        mini.getbyName("FDate1").setValue(nowDate);
        mini.getbyName("FDate2").setValue(nowDate);
        //mini.getbyName("FDate3").setValue(mini.getbyName("FDate2").getValue());
        LoadListData("0");
        LoadAgentList();
        mini.getbyName("delrow").disable();
        //mini.getbyName("new").disable();
    }

    //加载资料列表
    function LoadListData(mClassID) {
        var mParentID = mini.getbyName("FCorpItemID").getValue();
        var mDateType = "0";
        if (mini.getbyName("FAtDate").checked == true) mDateType = "1";
        var mAtClass = "0";
        if (mini.getbyName("FAtClass").checked == true) mAtClass = "1";
        var mAtApply = "0";
        if (mini.getbyName("FAtApply").checked == true) mAtApply = "1";
        var cDate1 = mini.getbyName("FDate1").getFormValue();
        var cDate2 = mini.getbyName("FDate2").getFormValue();
        var json = "[{";
        json = json + "'mNumber':" + "'" + mini.getbyName("FSearchKey1").getValue() + "',";
        json = json + "'mClassID':" + "'" + mClassID + "',";
        json = json + "'mParentID':" + "'" + mParentID + "',";
        json = json + '"mDate1":' + '"' + cDate1 + '",';
        json = json + '"mDate2":' + '"' + cDate2 + '",';
        json = json + '"mAtDate":' + '"' + mDateType + '",';
        json = json + '"mAtClass":' + '"' + mAtClass + '",';
        json = json + '"mAtApply":' + '"' + mAtApply + '",';
        json = json + "'mSystemAppID':" + "'" + parent.window.getSystemAppID() + "'";
        json = json + "}]";
        var grid = mini.get("datagrid1");
        grid.load({ mydata: json });

        mExportDataUrl = grid.url;        
        mExportDataJson = json;//导出
    }

    //加载资料列表
    function LoadAgentList() {
        var json = "[{";
        json = json + "'search':" + "'" + mini.getbyName("FSearchKey").getValue() + "',";
        json = json + "'mSystemAppID':" + "'" + parent.window.getSystemAppID() + "'";
        json = json + "}]";
        var grid = mini.get("datagrid2");
        grid.load({ mjson: json });
    }

    function setSaveSign() {
        var grid = mini.get("datagrid1");
        var rows = grid.getChanges();
        var json = mini.encode(rows);
        $.post("CheckSign", { json: json, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                grid.reload();
                mini.showTips({ content: '保存成功', state: "success", x: "center", y: "top", timeout: 3000 });
            }
            else {
                mini.showTips({ content: '保存失败 ' + ret.error, state: "danger", x: "center", y: "top", timeout: 3000 });
            }
        });
    }

    function setkeyPress() {
        if (event.keyCode == 13) {
            LoadAgentList();
        }
    }

    function setkeyPress1() {
        if (event.keyCode == 13) {
            LoadListData(0);
        }
    }

    function newBill() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        var grid2 = mini.get("datagrid2");
        var row2 = grid2.getSelected();
        if (row2) {
            mini.open({
                url: "/Corp/CopySon",
                title: "新增商户资料", width: 450, height: 350,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { FItemID: 0, FClassID: row2.FItemID };
                    if (row)
                        data = { FItemID: row.FItemID, FNumber: row.FNumber, FName: row.FName, FClassID: row2.FItemID };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    var grid = mini.get("datagrid1");
                    grid.reload();
                }
            });
        } else {
            mini.alert("请选中一个服务商");
        }
    }

    //修改资料
    function modify() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/Corp/CorpInfo",
                title: "商户资料", width: 670, height: 460,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = {
                        FItemID: row.FItemID, FNumber: row.FNumber, FName: row.FName, FManager: row.FManager,
                        FTelephone: row.FTelephone, FAddress: row.FAddress, FEMail: row.FEMail, FBillPrtName: row.FBillPrtName,
                        FCustName: row.FCustName, FRemark: row.FRemark, FAppID: row.APPID, FAppsecret: row.APPSECRET
                    };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    //修改代理
    function modifyAgent() {
        var grid = mini.get("datagrid2");
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/Corp/AgentInfo",
                title: "服务商资料", width: 650, height: 320,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = {
                        FItemID: row.FItemID, FNumber: row.FNumber, FName: row.FName, FManager: row.FManager, FTelephone: row.FTelephone,
                        FAddress: row.FAddress, FEmail: row.FEMail, FClusterID: row.FClusterID
                    };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    //代理充值
    function Recharge() {
        var grid = mini.get("datagrid2");
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/Corp/Recharge?type=9",
                title: "服务商充值", width: 650, height: 320,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = {
                        FItemID: row.FItemID, FNumber: row.FNumber, FName: row.FName, FManager: row.FManager, FTelephone: row.FTelephone,
                        FAddress: row.FAddress, FEmail: row.FEmail
                    };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    //设置代理
    function setAgent() {
        mini.confirm("确定要设置所选商家为服务商？", "提示",
            function (action) {
                if (action == "ok") {
                    var grid = mini.get("datagrid1");
                    var row = grid.getSelected();
                    if (row) {
                        $.post("setAgent", { json: row.FItemID }, function (data) {
                            var ret = mini.decode(data);
                            if (ret.status == 1) {
                                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                                var grid2 = mini.get("datagrid2");
                                grid2.reload();
                            }
                            else {
                                mini.alert(ret.error);
                            }
                        });
                    }
                    else {
                        mini.alert("请选中一条记录");
                    }
                }
            });
    }

    //注销前台
    function setClearPOS() {
        mini.confirm("确定要注销该商户的前台登陆信息吗？", "提示",
            function (action) {
                if (action == "ok") {
                    var grid = mini.get("datagrid1");
                    var row = grid.getSelected();
                    if (row) {
                        $.post("setClearPOS", { json: row.FItemID }, function (data) {
                            var ret = mini.decode(data);
                            if (ret.status == 1) {
                                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                            }
                            else {
                                mini.alert(ret.error);
                            }
                        });
                    }
                    else {
                        mini.alert("请选中一条记录");
                    }
                }
            });
    }

    //注销商户
    function delCorp() {
        mini.confirm("确定要注销该商户吗？", "提示",
            function (action) {
                if (action == "ok") {
                    var grid = mini.get("datagrid1");
                    var row = grid.getSelected();
                    if (row) {
                        $.post("delCorp", { json: row.FItemID }, function (data) {
                            var ret = mini.decode(data);
                            if (ret.status == 1) {
                                grid.reload();
                                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                            }
                            else {
                                mini.alert(ret.error);
                            }
                        });
                    }
                    else {
                        mini.alert("请选中一条记录");
                    }
                }
            });
    }

    //取消代理
    function CancelAgent() {
        mini.confirm("确定要取消所选服务商？", "提示",
            function (action) {
                if (action == "ok") {
                    var grid = mini.get("datagrid2");
                    var row = grid.getSelected();
                    if (row) {
                        $.post("CancelAgent", { json: row.FItemID }, function (data) {
                            var ret = mini.decode(data);
                            if (ret.status == 1) {
                                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                                grid.reload();
                            }
                            else {
                                mini.alert(ret.error);
                            }
                        });
                    }
                    else {
                        mini.alert("请选中一条记录");
                    }
                }
            });
    }

    //设置有效期
    function setExpiry() {
        var grid2 = mini.get("datagrid2");
        var row2 = grid2.getSelected();
        if (row2) {
            var grid = mini.get("datagrid1");
            var row = grid.getSelected();            
            if (row) {
                if (row2.FItemID != row.FClassID)
                {
                    mini.alert("请选择对应的服务商来激活");
                    return;
                }

                mini.open({
                    url: "/Corp/ExpiryDate",
                    title: "系统激活", width: 800, height: 500,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = {
                            FItemID: row.FItemID, FNumber: row.FNumber, FName: row.FName, FClassID: row2.FCorpID
                        };
                        iframe.contentWindow.SetInfoData(data);
                    },
                    ondestroy: function (action) {
                        grid.reload();
                        //mini.get("datagrid2").reload();
                    }
                });

            } else {
                mini.alert("请选中一条记录");
            }
        }
        else {
            mini.alert("请在左边表中选一个服务商");
        }
    }

    function setParam() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/Corp/PayParam",
                title: "支付参数设置", width: 600, height: 400,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = {
                        FItemID: row.FItemID, FNumber: row.FNumber, FName: row.FName
                    };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    function select() {
        var grid = mini.get("datagrid2");
        var row = grid.getSelected();
        var mClassID = 0;
        if (row) mClassID = row.FItemID;
        LoadListData(mClassID);
    }

    function setPrice() {
        mini.open({
            url: "/Corp/setPrice",
            title: "服务商价格设置", width: 850, height: 470,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = {};
                iframe.contentWindow.SetInfoData(data);
            },
            ondestroy: function (action) {
            }
        });
   }
</script>